<template>
  <div class="linkCoupon">
    <!--{{selCouponData}}-->
    <el-dialog title="卡券列表" v-model="dialogTableVisible" size="large" class="formDialog" :close-on-click-modal="false">
      <!--搜索框-->
      <el-col :span="6" :offset="18" class="searchBox">
        <el-input placeholder="请选择卡券" icon="search" v-model.trim="search" @change="searchCoupon"></el-input>
      </el-col>
      <!--卡券列表-->
      <el-table max-height="280" :data="couponShow" highlight-current-row @current-change="handleCurrentChange" empty-text="对不起,未查找到相关内容" style="width: 100%" ref="singleTable" >
        <el-table-column type="index" width="70"></el-table-column>
        <el-table-column property="cardGetTime"     label="创建时间"      min-width="90"></el-table-column>
        <el-table-column property="cardDesc"        label="名字"          min-width="90"></el-table-column>
        <el-table-column property="cardTypeStr"     label="类型"          min-width="90"></el-table-column>
        <el-table-column property="faceValue"       label="面值"          min-width="90"></el-table-column>
        <el-table-column property="cardid"          label="卡券ID"        min-width="90"></el-table-column>
        <el-table-column property="issueCount"      label="发放数量"      min-width="90"></el-table-column>
        <el-table-column property="takeCount"       label="已领取数量"    min-width="90"></el-table-column>
        <el-table-column property="useCount"        label="已使用数量"    min-width="90"></el-table-column>
        <el-table-column property="takeDateStarted" label="领取开始时间"  min-width="90"></el-table-column>
        <el-table-column property="takeDateEnd"     label="领取结束时间"  min-width="90"></el-table-column>
        <el-table-column property="cardExprieTime"  label="使用结束时间"  min-width="90"></el-table-column>
      </el-table>
      <!--表单外层-->
      <el-form :model="couponForm" :rules="couponFromRules" ref="couponForm" label-width="100px">
        <!--活动条件选择-->
        <el-row v-if="isInvestAmount||isSendCard">
            <el-form-item label="活动条件" style="float: left;">
              <el-select v-model="rewardTypeWay" placeholder="请选择" @change="activityAlert(rewardTypeWay)">
                <el-option
                  v-for="item in activityConditionOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
        </el-row>
        <!--选择活动条件类型-->
        <el-row v-if="isInvestAmount||isSendCard">
            <el-form-item label="选择" prop="resource">
              <el-radio-group v-model="couponForm.type" v-if="moneyAmount" style="float: left;margin-top:10px">
                  <el-radio class="radio" label="SINGLE_AMOUNT">单笔
                  </el-radio>
                  <el-radio class="radio"  label="TOTAL_AMOUNT">累计</el-radio>
                  <el-radio class="radio"  label="SINGLE_AMOUNT_ONE_DAY">单日单笔
                  </el-radio>
                  <el-radio class="radio"  label="TOTAL_AMOUNT_ONE_DAY">单日累计
                  </el-radio>
              </el-radio-group>
              <el-radio-group  v-model="couponForm.type" v-else-if="isSendCard" style="float: left;margin-top:10px">
                <el-radio class="radio"  label="EACH_TOTAL_AMOUNT">每满</el-radio>
              </el-radio-group>
              <el-radio-group  v-model="couponForm.type" v-else style="float: left;margin-top:10px">
                  <el-radio class="radio"  label="TOTAL_COUNT">累计</el-radio>
                  <el-radio class="radio"  label="TOTAL_COUNT_ONE_DAY">单日累计</el-radio>
              </el-radio-group>
            </el-form-item>
        </el-row>
        <!--输入金额（笔数）-->
        <el-row v-if="isInvestAmount||isSendCard">
          <el-col :span="10">
              <el-form-item prop="conditionAmount" label="投资金额(元)" v-if="moneyAmount||isSendCard" >
                <el-input v-model="couponForm.conditionAmount" placeholder="请输入相应金额" ></el-input>
              </el-form-item>
              <el-form-item prop="conditionCount" label="投资笔数(笔)" v-else>
                <el-input v-model="couponForm.conditionCount" placeholder="请输入相应数字"></el-input>
              </el-form-item>
          </el-col>
        </el-row>
        <!--赠送数量-->
        <el-row>
            <el-col :span="10">
              <el-form-item prop="cardNum" label="赠送数量">{{couponForm.cardNum}}
                <el-input v-model="couponForm.cardNum " placeholder="请输入相应数字" ></el-input>
              </el-form-item>
            </el-col>
        </el-row>
        <!--限制张数-->
        <el-row v-if="isSendCard">
          <el-col :span="10">
            <el-form-item prop="limitNum" label="每月限制张数">
              <el-input v-model="couponForm.limitNum" placeholder="请输入相应数字" ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
          <span slot="footer" class="dialog-footer">
               <el-button type="primary" @click="submitCoupon('couponForm')" :disabled="submitBtnDis">确 定</el-button>
               <el-button @click="dialogTableVisible = false">取 消</el-button>
          </span>
    </el-dialog>
    <el-form ref="form1" :model="form1" label-width="80px">
      <el-row>
        <el-col :span="2">*添加卡券</el-col>
        <el-col :span="1" >
          <el-button class="el-icon-plus" @click="showCouponList"></el-button>
        </el-col>
      </el-row>
      <!--选中的卡券列表-->
      <el-table :data="selCouponData" style="width: 100%;overflow: hidden;" v-if="isInvestAmount" class="couponTable">
        <el-table-column prop="rewardTypeWay"   label="投资条件"  min-width="50"></el-table-column>
        <el-table-column prop="rewardTypeText"  label="附加条件"  min-width="50"></el-table-column>
        <el-table-column prop="conditionAmount" label="投资金额"  min-width="40"></el-table-column>
        <el-table-column prop="conditionCount"  label="满送笔数"  min-width="40"></el-table-column>
        <el-table-column prop="cardId"          label="卡券ID"    min-width="100"></el-table-column>
        <el-table-column prop="cardDesc"        label="卡券名称"  min-width="50"></el-table-column>
        <el-table-column prop="cardType"        label="卡券类型"  min-width="50"></el-table-column>
        <el-table-column prop="cardFaceValue"   label="卡券面值"  min-width="50"></el-table-column>
        <el-table-column                        label="操作"      min-width="50">
          <template scope="scope">
            <el-button @click.native.prevent="disabledRow(scope.$index,selCouponData)" v-if="hasPublish(scope.row)" :disabled="hasDisabled(scope.row)" type="text" size="small" >禁用</el-button>
            <el-button @click.native.prevent="deleteRow(scope.$index,selCouponData)" type="text" size="small" v-else>删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="selCouponData" style="width: 100%" v-else-if="isSendCard" class="couponTable">
        <el-table-column prop="rewardTypeWay"   label="活动条件"  min-width="50"></el-table-column>
        <el-table-column prop="rewardTypeText"   label="获取规则"  min-width="50"></el-table-column>
        <el-table-column prop="conditionAmount" label="投资金额"    min-width="100"></el-table-column>
        <el-table-column prop="cardNum"         label="获取数量"  min-width="50"></el-table-column>
        <el-table-column prop="limitNum"        label="每月限制张数"  min-width="50"></el-table-column>
        <el-table-column prop="cardId"          label="卡券ID"  min-width="50"></el-table-column>
        <el-table-column prop="cardDesc"        label="卡券名称"  min-width="50"></el-table-column>
        <el-table-column prop="cardFaceValue"   label="卡券面值"  min-width="50"></el-table-column>
        <el-table-column                        label="操作"      min-width="50">
          <template scope="scope">
            <el-button @click.native.prevent="disabledRow(scope.$index,selCouponData)" v-if="hasPublish(scope.row)" :disabled="hasDisabled(scope.row)" type="text" size="small" >禁用</el-button>
            <el-button @click.native.prevent="deleteRow(scope.$index,selCouponData)" v-else type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="selCouponData" style="width: 100%" v-else class="couponTable">
        <el-table-column prop="actType"         label="活动类型"  min-width="50"></el-table-column>
        <el-table-column prop="cardNum"         label="赠送数量"  min-width="50"></el-table-column>
        <el-table-column prop="cardId"          label="卡券ID"    min-width="100"></el-table-column>
        <el-table-column prop="cardDesc"        label="卡券名称"  min-width="50"></el-table-column>
        <el-table-column prop="cardType"        label="卡券类型"  min-width="50"></el-table-column>
        <el-table-column prop="cardFaceValue"   label="卡券面值"  min-width="50"></el-table-column>
        <el-table-column                        label="操作"      min-width="50">
          <template scope="scope">
            <el-button @click.native.prevent="disabledRow(scope.$index,selCouponData)" v-if="hasPublish(scope.row)" :disabled="hasDisabled(scope.row)" type="text" size="small" >禁用</el-button>
            <el-button @click.native.prevent="deleteRow(scope.$index,selCouponData)" v-else type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--如果是创建界面-->
      <el-row v-if="isCreate">
        <el-button @click="prev" class="buttonStep">上一步</el-button>
        <el-button @click="finish" v-if="createFinish" class="buttonStep">完成</el-button>
        <el-button @click="nextStep" v-else class="buttonStep">下一步</el-button>
      </el-row>
      <el-row v-else>
        <el-button @click="submit()" class="buttonStep">保存</el-button>
      </el-row>
    </el-form>
  </div>
</template>
<script>
  import {postLog} from 'api/common/index.js'
  export default{
    //pageType页面类型是编辑还是创建 couponInfo 请求到的该活动所有数据
    props: ['pageType', 'couponInfo', 'info'],
    data () {
      //赠送卡券的验证规则
      let checkCard = (rule, value, callback) => {
        console.log(value);
        console.log(typeof value);
        if (!value) {
          return callback(new Error('赠送数量不能为空且大于0!!!'));
        }
        value = Number(value);
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error('请输入数字值'));
          } else {
            if (value > this.remainCount) {
              callback(new Error('赠送数量必须小于等于卡券剩余数量'));
            } else if (value <= 0) {
              callback(new Error('赠送数量不能为空且大于0'));
            } else {
              callback();
            }
          }
        }, 1000);
      };
      //金额，笔数的验证
      let checkNum = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('输入不能为空且大于0'));
        }
        value = Number(value);
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error('请输入数字值'));
          } else {
            if (value <= 0) {
              callback(new Error('输入值不能为空且大于0'));
            } else {
              callback();
            }
          }
        }, 1000);
      };
      let checkLimit = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('限制张数不能为空'));
        }
        value = Number(value);
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error('请输入数字值'));
          } else {
            if (value <= 0) {
              callback(new Error('输入值不能为空且大于0'));
            } else if (value % this.couponForm.cardNum != 0) {
              console.log(this.couponForm.cardNum);
              console.log(typeof (this.couponForm.cardNum));
              console.log(value);
              console.log(value % this.cardNum);
              callback(new Error('输入值必须为赠送张数的倍数'))
            } else {
              callback();
            }
          }
        }, 1000);
      }
      return {
        isSendCard: false,
//          确定按钮
        submitBtnDis: false,
//        卡券列表弹框提交的数据
        couponForm: {
          activityId: '',                                    //活动Id
          cardId: null,                                     //卡券Id
          cardNum: null,                                    //赠送数量
          conditionAmount: null,                            //金额
          conditionCount: null,                             //笔数
          type: 'SINGLE_AMOUNT',                             //类型
          limitNum: null
        },
//         验证规则
        couponFromRules: {
//         赠送卡券数量
          cardNum: [
            {validator: checkCard, trigger: 'blur'}
          ],
//          验证金额
          conditionAmount: [
            { min: 0, max: 10, message: '投资金额不能超过10位', trigger: 'blur' },
            {validator: checkNum, trigger: 'blur'}
          ],
//          验证笔数
          conditionCount: [
            { min: 0, max: 10, message: '投资笔数不能超过10位', trigger: 'blur' },
            {validator: checkNum, trigger: 'blur'}
          ],
          limitNum: [
              { min: 0, max: 10, message: '限制张数不能超过10位', trigger: 'blur' },
            {validator: checkLimit, trigger: 'blur'}
          ]
        },
        isCreate: true,                                      //判断为创建
        search: '',                                          //搜索框的输入
        currentRow: {},                                      //选中的卡券
        remainCount: '',                                     //剩余的卡券
        moneyAmount: true,                                  //根据金额来计算
        isInvestAmount: false,                              //是否投资满额
        createFinish: false,                               //是否完成创建,用于判断是下一步还是完成
        dialogTableVisible: false,                          //弹框是否显示
        actType: '',                                         //活动类型
        selCouponData: [],                                   //展现在列表的初始化信息
        userSelCouponData: [],                               //添加的卡券信息
        form1: {
          activityId: '', //活动id
          couponRewardConditions: []                        //选中的卡券列表
        },
        couponData: [],                                    //请求到的卡券列表数据
        couponShow: [],                                     //展现在卡券列表的卡券
        rewardTypeWay: 'investMoney',                       //活动条件,
        //活动条件类型
        activityConditionOptions: [
          {
            value: 'investCount',
            label: '投资笔数'
          }, {
            value: 'investMoney',
            label: '投资满额'
          }
        ]
      }
    },
    created () {
//      页面判断
      if (this.pageType == 'edit') {
        //      设置该活动的活动类型
        this.actType = this.$route.params.type;
        this.isCreate = false;
        this.form1.activityId = this.$route.params.actId;
        this.couponForm.activityId = this.$route.params.actId;
        this.showByActivityType(this.$route.params.type);
      } else {
        this.actType = this.$store.state.actType.activityType;
//      根据活动类型判断显示，是投资的显示选择投资条件等
        this.showByActivityType(this.$store.state.actType.activityType);
//      如果创建页面，而活动只有两个模块,就显示完成按钮
        if (this.$store.state.actType.modulesCount == 2) {
          this.createFinish = true
        }
      }
    },
    mounted () {
      this.$http.get('/api-active/v1/api/coupon/api/coupon/list?status=ENABLE')
        .then((response) => {
          let data = response.body;
          if (data.resultCode == '200') {
            this.couponData = data.result;
          }
        });
    },
    watch: {
//        监听父组件传入的卡券信息
      couponInfo (val, oldval) {
        this.initCardTable(val);
      },
      couponData (val, oldval) {
        this.couponShow = val;
      }
    },
    methods: {
//  展示卡券列表
      showCouponList () {
        this.dialogTableVisible = true;
        this.submitBtnDis = false;
      },
//  搜索卡券
      searchCoupon () {
        let str = this.search;
        let arr = [];
        for (let key in this.couponData) {
          if (this.couponData[key].cardDesc.indexOf(str) >= 0) {
            arr.push(this.couponData[key]);
          }
        }
        this.couponShow = arr;
      },
//  选择卡券
      handleCurrentChange (val) {
        // debugger;
        console.log(val);
        this.currentRow = val;
        if (val != undefined) {
          this.couponForm.cardId = val.cardid;
          this.remainCount = val.issueCount - val.takeCount;
        }
      },
//  删除已选中的卡券
      deleteRow (index, rows) {
        // debugger;
        if (rows.length == 1) {
          this.$alert('卡券不能为空', '提示')
          return;
        }
        let params = {activityId: this.$route.params.actId, activityCouponId: rows[index].activityCouponId + ''};
        if (rows[index].activityCouponId) {
          if (this.form1.couponRewardConditions.length != 0) {
            this.$alert('请先保存添加的卡券', '提示');
            return;
          }
          this.$confirm('你确定要移除该卡券吗', '提示', {
//              type: 'warning'
          }).then(() => {
            this.$http.put('/api-active/v1/api/activityCenter/activity/deleteCoupon', params)
              .then((response) => {
                let data = response.body;
                if (data.resultCode == '200') {
                  rows.splice(index, 1);
                  this.$message({
                    type: 'success',
                    message: '页面已刷新!'
                  });
                  this.$emit('getData');
                  this.form1.couponRewardConditions = [];
                }
              });
          }).catch(() => {
          });
        } else {
          let addForm = this.form1.couponRewardConditions;
          for (let key in addForm) {
            if (this.actType = 'PRODUCT_INVESTMENT') {
              if (addForm[key].conditionAmount == rows[index].conditionAmount &&
              addForm[key].conditionCount == rows[index].conditionCount &&
              addForm[key].type == rows[index].rewardType) {
                addForm.splice(key, 1);
              }
            } else if (addForm[key].cardId == rows[index].cardId) {
              addForm.splice(key, 1);
            }
          }
          rows.splice(index, 1);
        }
      },
//  禁用卡券
      disabledRow (index, row) {
        if (this.form1.couponRewardConditions.length != 0) {
          this.$alert('请先保存添加的卡券', '提示');
          return;
        }
        this.$confirm('你确定要禁用该卡券吗?', '提示', {
          //type: 'warning'
        }).then(() => {
          this.$http.put('/api-active/v1/api/activityCenter/activity/disableCoupon?activityId=' + this.$route.params.actId + '&activityCouponId=' + row[index].activityCouponId)
            .then((response) => {
              let data = response.body;
              this.$message({
                type: 'success',
                message: '刷新已页面!'
              });
              this.$emit('getData');
              this.form1.couponRewardConditions = [];
            })
        }).catch(() => {

        });
      },
//  置灰禁用按钮
      hasDisabled (row) {
        if (row.enable == 'NO') {
          return true
        } else {
          return false
        }
      },
//  根据发布显示禁止按钮,
      hasPublish (row) {
        if (this.$route.params.status == 1 && row.activityCouponId != undefined) {
          return true;
        } else {
          return false;
        }
      },
//  根据活动条件显示不同内容
      activityAlert (label) {
        if (label === 'investCount') {
          this.moneyAmount = false;
          this.couponForm.conditionAmount = null;
          this.couponForm.type = 'TOTAL_COUNT'
        } else if (label === 'investMoney' && this.isSendCard == false) {
          this.moneyAmount = true;
          this.couponForm.conditionCount = null;
          this.couponForm.type = 'SINGLE_AMOUNT'
        } else if (label === 'investMoney' && this.isSendCard == true) {
          this.moneyAmount = false;
          this.couponForm.conditionCount = null;
          this.couponForm.type = 'EACH_TOTAL_AMOUNT'
        }
      },
//  根据活动类型判断显示，是投资的显示选择投资条件等
      showByActivityType (type) {
        if (type === 'PRODUCT_INVESTMENT') {
          this.isInvestAmount = true;
        } else if (type == 'FINANCIAL_CUSTOMER_INVESTMENT') {
          this.isSendCard = true;
          this.activityConditionOptions = [{
            value: 'fullPerformance',
            label: '业绩满额'
          }];
          this.rewardTypeWay = 'fullPerformance';
          this.moneyAmount = false;
          this.couponForm.type = 'EACH_TOTAL_AMOUNT';
          this.couponForm.conditionCount = null;
        } else {
          this.couponForm.type = 'NONE';
          this.couponForm.conditionAmount = null;
          this.couponForm.conditionCount = null;
        }
      },
//  提交,弹出框提交卡券数据
      submitCoupon (couponForm) {
        if (this.currentRow == undefined) {
          this.$alert('请选择卡券', '提示')
          return
        }
        this.submitBtnDis = true;
        this.$refs[couponForm].validate((valid) => {
          if (valid) {
            this.showCardTable(this.couponForm, this.rewardTypeWay, this.currentRow);
            this.dialogTableVisible = false;
          } else {
            this.submitBtnDis = false;
            return false;
          }
        });
      },
//  编辑页面初始化卡券信息,展示层
      initCardTable (coupons) {
        for (let key in coupons) {
          coupons[key].cardDesc = coupons[key].cardName
          coupons[key].actType = this.info.typeText;
        }
        this.selCouponData = coupons;
      },
//  卡券列表组件提交的数据（卡券的表单，卡券投资条件，卡券其他信息）
      showCardTable (card, rewardTypeWay, couponInformation) {
        console.log(card);
        let objCard = Object.assign({}, card);
        console.log(objCard);
        let selCoupon = {};
        selCoupon.limitNum = card.limitNum;
        selCoupon.cardId = card.cardId;                                   //卡券ID
        selCoupon.cardNum = card.cardNum;                                 //卡券赠送数量
        if (card.type == 'SINGLE_AMOUNT') {                                //卡券投资附加条件
          selCoupon.rewardTypeText = '单笔';
          selCoupon.rewardType = 'SINGLE_AMOUNT';
        } else if (card.type == 'TOTAL_AMOUNT') {
          selCoupon.rewardTypeText = '累计'
          selCoupon.rewardType = 'TOTAL_AMOUNT'
        } else if (card.type == 'SINGLE_AMOUNT_ONE_DAY') {
          selCoupon.rewardTypeText = '单日单笔'
          selCoupon.rewardType = 'SINGLE_AMOUNT_ONE_DAY'
        } else if (card.type == 'TOTAL_AMOUNT_ONE_DAY') {
          selCoupon.rewardTypeText = '单日累计'
          selCoupon.rewardType = 'TOTAL_AMOUNT_ONE_DAY'
        } else if (card.type == 'TOTAL_COUNT') {
          selCoupon.rewardTypeText = '累计'
          selCoupon.rewardType = 'TOTAL_COUNT'
        } else if (card.type == 'TOTAL_COUNT_ONE_DAY') {
          selCoupon.rewardTypeText = '单日累计'
          selCoupon.rewardType = 'TOTAL_COUNT_ONE_DAY'
        } else if (card.type = 'EACH_TOTAL_AMOUNT') {
          selCoupon.rewardTypeText = '每满'
          selCoupon.rewardType = 'EACH_TOTAL_AMOUNT'
        }
        selCoupon.conditionAmount = card.conditionAmount;               //根据金额
        selCoupon.conditionCount = card.conditionCount;                 //根据笔数
        selCoupon.cardName = couponInformation.cardDesc;                //卡券名称
        selCoupon.cardDesc = couponInformation.cardDesc;                //卡券名称  (用于解决后端字段名不统一)
        selCoupon.cardType = couponInformation.cardTypeStr;             //卡券类型
        selCoupon.cardFaceValue = couponInformation.faceValue;          //卡券面值
        if (this.pageType == 'edit') {
          selCoupon.actType = this.info.typeText;                    //活动类型
        } else if (this.pageType == 'create') {
          let type = this.$store.state.actType.activityType;
          if (type == 'REGISTRATION') {
            selCoupon.actType = '注册即送'
          } else if (type == 'PRODUCT_INVESTMENT') {
            selCoupon.actType = '产品投资'
          } else if (type == 'SPECIAL') {
            selCoupon.actType = '特别活动'
          } else if (type == 'INTRODUCTION') {
            selCoupon.actType = '活动推广'
          } else if (type == 'FINANCIAL_CUSTOMER_INVESTMENT') {
            selCoupon.actType = '理财师送券'
          }
        }//活动类型
        if (rewardTypeWay == 'investMoney') {
          selCoupon.rewardTypeWay = '按金额'
        } else if (rewardTypeWay == 'investCount') {
          selCoupon.rewardTypeWay = '按笔数'
        } else if (rewardTypeWay == 'fullPerformance') {
          selCoupon.rewardTypeWay = '按金额'
        } else {
          selCoupon.rewardTypeWay = '无条件'
        }
        //投资条件
        if (this.actType == 'PRODUCT_INVESTMENT') {
          this.DuplicateRemovalAccordInvest(selCoupon, this.selCouponData, objCard)
          this.rewardTypeWay = 'investMoney';
        } else if (this.isSendCard == true) {
          this.DuplicateRemovalAccordSendCard(selCoupon, this.selCouponData, objCard);
          this.rewardTypeWay = 'fullPerformance';
        } else {
          this.DuplicateRemovalAccordCardId(selCoupon, this.selCouponData, objCard)
        }
        this.$refs['couponForm'].resetFields();
        this.$refs.singleTable.setCurrentRow();
        return false;
      },
      DuplicateRemovalAccordSendCard (obj, arr, card) {
        for (let key in arr) {
          if (arr[key].conditionAmount == obj.conditionAmount &&
          arr[key].cardId == obj.cardId &&
          arr[key].enable == 'YES') {
            return false;
          }
        }
        obj.enable = 'YES';
        arr.push(obj);
        this.form1.couponRewardConditions.push(card);
      },
      DuplicateRemovalAccordInvest (obj, arr, card) {
        for (let key in arr) {
          if (arr[key].conditionAmount == obj.conditionAmount &&
          arr[key].conditionCount == obj.conditionCount &&
          arr[key].type == obj.type &&
          arr[key].rewardType == obj.rewardType &&
          arr[key].enable == 'YES') {
            return false;
          }
        }
        obj.enable = 'YES';
        arr.push(obj);
        this.form1.couponRewardConditions.push(card);
      },
      DuplicateRemovalAccordCardId (obj, arr, card) {
        for (let key in arr) {
          if (arr[key].cardId == obj.cardId) {
            return false
          }
        }
        arr.push(obj);
        this.form1.couponRewardConditions.push(card);
      },
//  编辑卡券提交
      submit () {
        if (this.form1.couponRewardConditions.length == 0) {
          this.$alert('修改成功', '提示');
          return false
        }
        this.$http.put('/api-active/v1/api/activityCenter/activity/coupon', this.form1)
          .then((response) => {
            let data = response.body;
            if (data.resultCode == '200') {
              postLog('ACTIVITY_LIST_EDIT', this.form1.activityId, '', this.form1);
              this.form1.couponRewardConditions = [];
              this.$alert('修改成功', '提示');
              this.$emit('getData');
            }
          })
      },
//  上一步
      prev () {
        this.$emit('back', {showModules: 'basic', active: 2})
      },
//  下一步
      nextStep () {
        if (this.form1.couponRewardConditions.length == 0) {
          this.$alert('请选择卡券', '提示')
          return
        }
        this.$emit('getCouponData', {couponInfoFrom: this.form1, showModules: 'product', active: 4})
      },
//  完成
      finish () {
        if (this.form1.couponRewardConditions.length == 0) {
          this.$alert('请选择卡券', '提示')
          return false
        }
        this.$emit('startCreateAct', {couponInfoFrom: this.form1, finishStep: 2})
      }
    }
  }

</script>
<style lang="less">
@greenStyle:#63c5ce;
@orangeStyle:#f7931e;
  body #app .linkCoupon{
    .buttonStep{
      width: 200px;
      border:0;
      background: @greenStyle;
      margin:30px 40px 0 40px;
      color:#fff;
    }
    .couponTable{
      margin-top:40px;
    }
    .el-table{
      th {
        background: #fff;
        .cell {
          font-size: 0.875rem;
          min-height:2.5rem;
          line-height:2.5rem;
          padding-left: 3px;
          padding-right: 3px;
          background: #fff;
          text-align: center;
        }
      }
      .el-table__body{
        color:#666666;
        overflow-y: auto;
        .cell{
          font-size: 0.875rem;
          padding-left:3px;
          padding-right:3px;
          text-align: center;
        }
      }
      .el-button--text{
        color:@greenStyle;
        margin:0 5px;
      }
      .el-button--small{
        font-size: 0.875rem;
      }
      .is-disabled{
        color:#bfcbd9;
      }
    }
  }
</style>
